package com.bytedance.modulizeandrouter

import android.content.Intent
import android.util.Log
import android.widget.Button
import android.widget.Toast
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.bytedance.common.base.BaseActivity
import com.bytedance.common.constants.RouterPathConstants

@Route(path = RouterPathConstants.TEST_ACTIVITY_PATH)
class TestActivity : BaseActivity() {
    private lateinit var goToPersonalPage: Button
    companion object {
        const val REQUEST_CODE = 100
        const val RESULT_CODE = 101
    }
    override fun getLayoutId() = R.layout.activity_test

    override fun initData() {
        goToPersonalPage = findViewById(R.id.go_to_personal_page)
    }

    override fun initListener() {
        goToPersonalPage.setOnClickListener {
//            open(RouterPathConstants.PERSONAL_ACTIVITY_PATH)
            ARouter.getInstance().build(RouterPathConstants.PERSONAL_ACTIVITY_PATH).navigation(this,
                    REQUEST_CODE,object: NavigationCallback{
                    override fun onFound(postcard: Postcard?) {
                        Log.e("cx","路由成功")
                    }

                    override fun onLost(postcard: Postcard?) {
                        Log.e("cx","路由失败")
                    }

                    override fun onArrival(postcard: Postcard?) {
                        Log.e("cx","跳转成功")
                    }

                    override fun onInterrupt(postcard: Postcard?) {
                        Log.e("cx","被拦截")
                    }

                })
        }
    }

    fun showToast(msg: String) {
        Toast.makeText(this,msg,Toast.LENGTH_SHORT).show()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == REQUEST_CODE && resultCode == RESULT_CODE) {
            showToast("返回成功")
        }
    }



}